//
//  MGCommon.swift
//  FuncTest
//
//  Created by li on 2025-05-17.
//

import SwiftUI


public protocol MGViewVisibility { }


public extension MGViewVisibility where Self == MGVisibleView {
	
	public static var visible: MGVisibleView {
		get {
			.init()
		}
	}
	
	public static var hidden: MGHiddenView {
		get {
			.init()
		}
	}
	
	public static var empty: MGEmptyView {
		get {
			.init()
		}
	}
}



public struct MGVisibleView: MGViewVisibility {
	public func hidden(_ condition: @autoclosure () -> Bool) -> MGViewVisibility {
		condition() ? MGHiddenView() : self
	}
	
	public func empty(_ condition: @autoclosure () -> Bool) -> MGViewVisibility {
		condition() ? MGEmptyView() : self
	}
	
}
public struct MGHiddenView:  MGViewVisibility {}
public struct MGEmptyView: MGViewVisibility {}


public extension View {
	@ViewBuilder
	public func mgViewVisibility(_ visibility: MGViewVisibility) -> some View {
		
		Group {
			if visibility is MGEmptyView  {
				EmptyView()
			}else if visibility is MGHiddenView {
				hidden()
			}else {
				self
			}
		}
	}
}
